const data = [1, 2, 3, 0, 0, 0, 5, 2, 0, 1, 0, 0, 2];

function fn(arr) {
  for (let i = 0; i < arr.length; i++) {
    if (arr[i] === 0) {
      let zeroCount = 1
      while (arr[i + 1] != undefined && arr[i + 1] === 0) {
        i++
        zeroCount++
      }
      if (zeroCount >= 3) {
        let newArr = arr.slice(0, i - zeroCount + 1)
        let restArr = arr.slice(i + 1)
        arr = [...newArr, ...restArr]
        i = i - zeroCount
      }
    }
  }
  return arr
}
console.log(fn(data));